package com.example.killer.defaultadapter.Adapter;

import android.content.Context;
import android.util.Log;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.AbsListView;
import android.widget.BaseAdapter;
import android.widget.ImageView;
import android.widget.TextView;

import com.example.killer.defaultadapter.Globals;
import com.example.killer.defaultadapter.MainActivity;
import com.example.killer.defaultadapter.R;

import java.util.List;
import java.util.Map;

/**
 * Created by killer on 2016/4/15.
 */
public class MyAdapter extends BaseAdapter{
    private Context ctx;
    private List<Map<String, Object>> values;

    public MyAdapter(Context ctx, List<Map<String, Object>> values) {
        this.ctx = ctx;
        this.values = values;
    }


    @Override
    public int getCount() {
        return values.size();
    }

    @Override
    public Object getItem(int position) {
        return values.get(position);
    }

    @Override
    public long getItemId(int position) {
        return position;
    }

    @Override
    public View getView(int position, View convertView, ViewGroup parent) {
        if (convertView ==null){
            convertView = LayoutInflater.from(ctx).inflate(R.layout.list_view,null);

            convertView.setLayoutParams(new AbsListView.LayoutParams(ViewGroup.LayoutParams.MATCH_PARENT, Globals.SCREEN_HEIGHT / 10));
            Log.i("killer", " Globals.SCREEN_HEIGHT:  " + Globals.SCREEN_HEIGHT / 10);


        }

        TextView title = (TextView) convertView.findViewById(R.id.line_title);
        TextView time = (TextView) convertView.findViewById(R.id.line_time);
        TextView img = (TextView) convertView.findViewById(R.id.line_img1);


        Map<String, Object> map = values.get(position);
        title.setText(map.get("title").toString());
        time.setText(map.get("time").toString());
        img.setBackgroundResource((Integer) map.get("img"));
       img.getLayoutParams().height = Globals.SCREEN_HEIGHT / 10;

        return convertView;
    }
}
